package com.sooth.micro.app.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.dream.system.config.Page;
import com.sooth.common.core.domain.R;
import com.sooth.common.dream.model.PageModel;
import com.sooth.common.log.annotation.Log;
import com.sooth.common.web.core.BaseController;
import com.sooth.micro.app.service.IMicroAppService;
import com.sooth.micro.app.view.MicroAppBo;
import com.sooth.micro.app.view.MicroAppDto;
import com.sooth.micro.app.view.MicroAppVo;
import com.sooth.micro.entity.view.MicroEntityBo;
import com.sooth.micro.entity.view.MicroEntityVo;
import com.sooth.micro.model.view.MicroModelBo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 在线应用
 *
 * @author moxa
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/micro/app")
public class MicroAppController extends BaseController {

    private final IMicroAppService service;

    /**
     * 获取在线应用列表
     */
    @SaCheckPermission("micro:app:query")
    @GetMapping("/list")
    public R<Page<MicroAppVo>> list(MicroAppDto microAppDto, PageModel pageModel) {
        return R.ok(service.selectPage(microAppDto, pageModel));
    }


    /**
     * 根据在线应用编号获取详细信息
     *
     * @param id 在线应用ID
     */
    @SaCheckPermission("micro:app:query")
    @GetMapping(value = "/query")
    public R<MicroAppBo> query(@RequestParam Long id) {
        return R.ok(service.selectById(id));
    }

    /**
     * 新增在线应用
     */
    @SaCheckPermission("micro:app:add")
    @Log(title = "在线应用管理", message = "新增在线应用")
    @PostMapping("/add")
    public R<Void> save(@Validated @RequestBody MicroAppBo microApp) {
        return toAjax(service.insert(microApp));
    }

    /**
     * 修改在线应用
     */
    @SaCheckPermission("micro:app:edit")
    @Log(title = "在线应用管理", message = "修改在线应用")
    @PutMapping("/edit")
    public R<Void> edit(@Validated @RequestBody MicroAppBo microApp) {
        return toAjax(service.updateById(microApp));
    }

    /**
     * 删除在线应用
     *
     * @param id 在线应用ID
     */
    @SaCheckPermission("micro:app:remove")
    @Log(title = "在线应用管理", message = "删除在线应用")
    @DeleteMapping("/remove")
    public R<Void> remove(@RequestParam Long id) {
        return toAjax(service.deleteById(id));
    }

    @SaCheckPermission("micro:app:query")
    @GetMapping("/getEntityVoList")
    public R<List<MicroEntityVo>> getEntityVoList(@RequestParam Long id) {
        return R.ok(service.getEntityVoList(id));
    }

    @SaCheckPermission("micro:app:query")
    @GetMapping("/getEntityBoList")
    public R<List<MicroEntityBo>> getEntityBoList(@RequestParam Long id) {
        return R.ok(service.getEntityBoList(id));
    }

    @SaCheckPermission("micro:app:query")
    @GetMapping("/getModelList")
    public R<List<MicroModelBo>> getModelList(@RequestParam Long id) {
        return R.ok(service.getModelList(id));
    }
}
